package cn.javase.concurrent._设计模式._同步模式之保护性暂停;

/**
 * 普通的GuardObject
 */
public class GuardedObject {

    private Object response;                    // 结果

    // 获取
    public Object get() {
        synchronized (this) {
            while (response == null) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            return response;
        }
    }

    // 设置并唤醒
    public void complete(Object response) {
        synchronized (this) {
            this.response = response;
            this.notifyAll();
        }
    }

}
